<!-- 底图切换组件 -->
<script setup>
import { onMounted, ref, defineProps, defineExpose, nextTick } from 'vue';
import LayerClose from '@/assets/images/base-map/layer-close.png';

const elId = `${Date.now()}${Math.random()}`;
const emit = defineEmits(['close']);
const close = ref(false);
// const el = ref();
const props = defineProps({
  show: {
    type: Boolean,
    default: false,
  },
  title: {
    type: String,
    default: '',
  },
  class: {
    type: String,
    default: '',
  },
});

const handleChangeShow = () => {
  close.value = true;
  // emit('close');
};

defineExpose({
  handleChangeShow,
});

onMounted(() => {
  nextTick(() => {
    document.getElementById(elId).addEventListener('transitionend', (e) => {
      if (e.target == document.getElementById(elId)) {
        if (e.propertyName == 'opacity') {
          emit('close');
        }
      }
    });
  });
});
</script>
<template>
  <div :id="elId" :class="`Border-Box absolute z-20 opacity-0  ${props.class} ${close ? 'opacity-0' : 'opacity-100'}`">
    <div class="line line-top-left"></div>
    <div class="line line-bottom-left"></div>
    <div class="line line-bottom-right"></div>
    <div class="bg"></div>
    <div class="top">
      <div class="bg-top"></div>
      <div class="text">{{ props.title }}</div>
      <div class="close-icon" @click="handleChangeShow()">
        <img :src="LayerClose" />
      </div>
    </div>
    <div class="content box-content">
      <slot></slot>
    </div>
  </div>
</template>

<style scoped lang="scss">
.Border-Box {
  right: 85px;
  bottom: 30px;
  width: 260px;
  border-right: 2px solid rgb(38, 196, 251);
  border-left: 2px solid rgb(38, 196, 251);
  transition: 1s;

  .line {
    position: absolute;
    z-index: 2;
    width: 14px;
    height: 3px;
    background: rgba(38, 196, 251, 1);
  }

  .line-top-left {
    top: 0;
    left: 0;
  }

  .line-bottom-left {
    bottom: 0;
    left: 0;
  }

  .line-bottom-right {
    right: 0;
    bottom: 0;
  }

  .bg {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
    width: 100%;
    height: 100%;
    background: rgba(0, 19, 26, 0.7);
    opacity: 1;
    backdrop-filter: blur(10px);
  }

  .top {
    width: 100%;
    height: 28px;
    padding-left: 13px;

    .text {
      position: absolute;
      z-index: 2;
      color: #fff;
      font-size: 14px;
      line-height: 28px;
    }

    .bg-top {
      position: absolute;
      top: 0;
      left: 0;
      z-index: 1;
      width: 100%;
      height: 28px;
      background: linear-gradient(90.44deg, rgba(38, 196, 251, 1) 0%, rgba(0, 13, 59, 0.19) 100%);
      opacity: 0.5;
    }

    .close-icon {
      position: absolute;
      top: -12px;
      right: -12px;
      z-index: 1;
      cursor: pointer;
    }

    img {
      display: block;
      width: 32px;
      height: 32px;
    }
  }

  .content {
    position: relative;
    z-index: 3;
    min-height: 60px;
    padding: 10px;
    padding-bottom: 20px;
    color: rgba(255, 255, 255, 0.5);
    color: #fff;
  }
}
</style>
